package demo1;

class Shape{
    public void draw(){
        System.out.println("画图形");
    }
}

class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("○");
    }
}

class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("方形");
    }
}

class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("△");
    }
}

class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("❀");
    }
}

public class TestDemo {

    public static void drawShape1(){
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String shape :
                shapes) {
            if (shape.equals("cycle")) {
                cycle.draw();
            }else if(shape.equals("rect")){
                rect.draw();
            }else if (shape.equals("flower")){
                flower.draw();
            }
        }
    }

    public static void drawShape(){
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        Shape[] shapes = {cycle,rect, cycle,rect,flower};
        for (Shape shape :
                shapes) {
            shape.draw();
        }
    }

    //向上转型
    public static void drawMap(Shape shape){
        shape.draw();
    }

    public static void main(String[] args) {
        drawShape1();
    }

    public static void main2(String[] args) {
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Triangle triangle = new Triangle();
        drawMap(cycle);
        drawMap(rect);
        drawMap(triangle);
    }

    public static void main1(String[] args) {
        Shape shape = new Cycle();
        shape.draw();
    }
}
